<?php
include('../../include/functions.inc.php');
$user = unserialize($_SESSION['user']);
$in = unserialize($_SESSION["invoice"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Pago de Cargos</title>
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <link href="../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <script src="../../js/jquery.js" type="text/javascript"></script>
        <script>jQuery.noConflict();</script>
        <script src="../../bootstrap/js/bootstrap.js"></script>
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/jsvalidate.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/prototype-date-extensions.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/datepicker.js"  type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        <style type="text/css">
            input,
            textarea{
                width: 300px;
            }
            select{
                width: 315px;
            }
        </style>
        <script type="text/javascript">
            validaTasa=function(){
                var error=new Array();
                if($F("TASA").empty() || isNaN(parseFloat($F("TASA")))){
                    error.push([$("TASA"), "Ingrese una tasa de cambio valida!"]);
                }
                if(error.size()>0){
                    return error.toArray();
                }

                return true;
            }
            var rsv;
            config=function(){
                rsv=new RSV({
                    formID: $(document.FACTURA),
                    errorFieldClass: "errorField",
                    rules: ["required,NIT,No. NIT es requerido!",
                        "required,NAME,Nombre de factura es requerido!",
                        "required,STATUS,Seleccione el estado de la factura!",
                        "function,validaTasa"],

                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212;",
                    onCompleteHandler:function(){
                        waitMsg("Guardando...");
                        var next=true;
                        /*if($F("STATUS")==2){
                            next=confirm("Esta seguro de guardar esta factura como pendiente de pago?");
                        }
                        if(next){
                            $(document.FACTURA).submit();
                        }else{
                            closeWait();
                        }*/
                        $(document.FACTURA).submit();
                    }
                });
            }



            verTotal=function(){
<?php if ($in["moneda"] == 2) { ?>
            $('TOTAL_REAL').value=Math.round((parseFloat($F('TASA'))*parseFloat($F('TOTAL')))*100)/100;
<?php } else { ?>
            $('TOTAL_REAL').value=parseFloat($F('TOTAL'));
<?php } ?>
        $('IVA').value=parseFloat($F('TOTAL_REAL'))*0.12;
    }


    addOnLoad(config);
        </script>
    </head>

    <body>

        <div id="rsvErrors"></div>
        <form id="FACTURA" name="FACTURA" method="GET" action="data.php">

            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th scope="col" colspan="2">
                        <ul class="nav nav-tabs">
                            <li class="active">
                                <a>Datos de Facturación</a>
                            </li>
                        </ul>
                    </th>
                </tr>
                <tr>
                    <th width="50%">&nbsp;</th>
                    <th  width="50%" valign="middle" scope="col">
                        <div class="btn-group">
                            <input type="button" name="cmdOk" id="cmdOk"  class="btn btn-info" value="Continuar" onclick="rsv.validate();" />
                            <input name="cancelar" type="button"  class="btn btn-info" value="Cancelar" id="cancelar" onclick="this.form.action='index.php';this.form.submit();" value="" />
                        </div>
                    </th>
                </tr>
                <tr>
                    <td colspan="2">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>FACTURA</td>
                                <td><?php echo $in["factura"]["SERIE"] ?>-?</td>
                            </tr>
                            <tr>
                                <td width="20%">NIT</td>
                                <td width="80%">
                                    <input type="hidden" id="SERIE" name="SERIE" value=""/>
                                    <input type="hidden" id="NUMERO" name="NUMERO" value=""/>
                                    <input name="NIT" type="text" id="NIT" value="<?php echo $in["nit"]; ?>" />
                                    <input name="operation" type="hidden" id="operation" value="invoice" /></td>
                            </tr>
                            <tr>
                                <td>NOMBRE </td>
                                <td><input name="NAME" type="text" id="NAME" value="<?php echo $in["nombre"]; ?>" />
                                    <input type="hidden" name="NOMBRE2" id="NOMBRE2" value="<?php echo $in["nombreEst"]; ?>" />          </td>
                            </tr>

                            <tr>
                                <td>DIRECCION</td>
                                <td><input name="ADDRESS" type="text" id="ADDRESS" size="50" value="<?php echo $in["dir"]; ?>" /></td>
                            </tr>
                            <tr>
                                <td>SUBTOTAL</td>
                                <td><input name="TOTAL"  type="text" id="TOTAL" readonly="readonly" value="<?php echo $in["total"]; ?>"  /></td>
                            </tr>
                            <tr>
                                <td>FECHA FACTURACION</td>
                                <td><input name="FECHAFAC" value="<?php echo date("Y-m-d"); ?>" readonly="readonly" type="text" id="FECHAFAC" size="30" />
                                    <script type="text/javascript">
                                        new Control.DatePicker('FECHAFAC', {icon: '../../js/protocalendar/calendar.png',dateFormat: 'yyyy-MM-dd'});
                                    </script>          </td>
                            </tr>
                            <?PHP if ($in["moneda"] == 2) { ?>
                                <tr>
                                    <td>TASA CAMBIO</td>
                                    <td><input name="TASA" type="text" id="TASA" value="8" onchange="verTotal();" onkeyup="verTotal();"  /></td>
                                </tr>
                            <?php } else { ?>
                                <input name="TASA" type="hidden" value="0" id="TASA" />
                            <?php } ?>
                            <tr>
                                <td>TOTAL</td>
                                <td><input type="text" name="TOTAL_REAL" id="TOTAL_REAL" readonly="readonly" /></td>
                            </tr>
                            <tr>
                                <td>IVA </td>
                                <td><input name="IVA" type="text" id="IVA"  readonly="readonly" /></td>
                            </tr>
                            <tr>
                                <td>ESTADO FACTURA</td>
                                <td><select name="STATUS" id="STATUS">
                                        <option value="1">PAGADA</option>
                                        <option value="2">EN TRAMITE</option>
                                        <option value="" selected="selected">Seleccionar</option>
                                    </select>          </td>
                            </tr>
                        </table></td>
                </tr>

            </table>
        </form>

        <script type="text/javascript">
            verTotal();
<?PHP if ($in["moneda"] == 2) { ?>  
        alert("Revisar tasa de cambio, se ha tomado por default Q8=$1");
<?PHP } ?>
        </script>

    </body>
</html>
